package com.kcht.rfid.rd30.secretary.core.command;


import com.kcht.rfid.rd30.secretary.exception.ParamException;

/**
 * 单个阅读器命令
 * */
public abstract class BasicReaderCommand {
    /**
     * 密钥
     * */
    private String pwd="无";


    /**
     * 获取高位密码
     * */
    public Integer getHighPwd(){
        return Integer.parseInt(pwd.substring(0, 4),16);
    }

    /**
     * 获取低位密码
     * */
    public Integer getLowPwd(){
        return Integer.parseInt(pwd.substring(4, 8),16);
    }

    public String getPwd() {
        return pwd;
    }

    /**
     * @throws ParamException pwd为空或不足8位，或不为16进制
     * */
    public void setPwd(String pwd) {
        if(pwd==null||pwd.length()!=8){
            throw new ParamException("pwd不能为空且长度必须为8");
        }
        try{
            Integer.parseInt(pwd,16);
        }catch (NumberFormatException e){
            throw new ParamException("pwd必须为16进制");
        }
        this.pwd = pwd;
    }
}
